//
//  MainViewController.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-17.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "MainViewController.h"
#import "AudioManager.h"

@implementation MainViewController

@synthesize starBackgroundA;
@synthesize starBackgroundB;
@synthesize menuLogoRecommend;
@synthesize menuSinglePlayer;
@synthesize menuInviteAFriend;
@synthesize menuOption;
@synthesize menuScore;
@synthesize menuHelp;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    starBackgroundA.frame = CGRectMake(0, 0, 480, 320);
    starBackgroundB.frame = CGRectMake(0, 320, 480, 320);
    [UIView animateWithDuration: 10.0  delay: 0.0
                        options: UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat
                     animations: ^(){
                         starBackgroundA.frame = CGRectMake(0, -320, 320, 480);
                         starBackgroundB.frame = CGRectMake(0, 0, 480, 320);
                     }
                     completion: nil
     ];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight
     || interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    
    return NO;
}

#pragma mark - touches

static UIImageView* curHighlightedImageView;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    UIImageView *touchView = (UIImageView*)[touch view] ;
    
    // 处理点击事件
    if ([touch view].tag < 100)
    {
        curHighlightedImageView.highlighted = NO;
        curHighlightedImageView = nil;
        [[AudioManager sharedInstance] PlaySFX:@"BackSFX"];
    }
    else
    {
        if (curHighlightedImageView == nil)
        {
            curHighlightedImageView = (UIImageView*)touchView;
            curHighlightedImageView.highlighted = YES;
            [[AudioManager sharedInstance] PlaySFX:@"SelectSFX"];
        }
        else if (curHighlightedImageView != touchView)
        {
            curHighlightedImageView.highlighted = NO;
            curHighlightedImageView = touchView;
            curHighlightedImageView.highlighted = YES;
            [[AudioManager sharedInstance] PlaySFX:@"SelectSFX"];
        }
        else if (curHighlightedImageView == touchView)
        {
            [[AudioManager sharedInstance] PlaySFX:@"ConfirmSFX"];
            [self jumpToScene:touchView];
        }
    }
}

- (void)jumpToScene:(UIImageView*)touchView
{
    switch (touchView.tag)
    {
        case 100:
            break;
        case 101:
            [self performSegueWithIdentifier:@"SegueToModeSelectScoreController" sender:self];
            break;
        case 102:
            break;
        case 103:
            [self performSegueWithIdentifier:@"SegueToOptionViewController" sender:self];
            break;
        case 104:
            [self performSegueWithIdentifier:@"SegueToHelpScoreController" sender:self];
            break;
        case 105:
            [self performSegueWithIdentifier:@"SegueToHelpViewController" sender:self];
            break;
        default:
            NSAssert(0, @"View Fault");
            break;
    }
}

@end
